package com.dgt.trade.service.impl;

import java.math.BigDecimal;
import java.util.Date;

import com.dgt.trade.entitys.UserBalance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dgt.trade.dao.IUserDao;
import com.dgt.trade.entitys.User;
import com.dgt.trade.service.IUserService;
import com.dgt.trade.utils.MD5Util;

@Service
public class UserServiceImpl implements IUserService {
	
	@Autowired
	private IUserDao userDao;
	
	@Override
	public User getMemberById(long user_id) {
		return userDao.getUserById(user_id);
	}

	@Override
	public User getMemberByMobile(String mobile) {
		return userDao.getUserByMobile(mobile);
	}

	@Override
	public boolean chekMobile(String mobile) {
		boolean flag=false;
		User user = userDao.getUserByMobile(mobile);
		if(user==null) {
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean registerUser(String mobile, String password,String SubAccountID) {
		boolean flag=false;
		User user = new User();
		user.setBalance((float) 0);
		user.setDataStatus(2);
		user.setMobile(mobile);
		user.setAvailableFund("0");
		user.setMarginFund("0");
		user.setBaseCurrency("CNY");
		user.setExecRate("1");
		user.setSubAccountID(SubAccountID);
		String newPwd =MD5Util.MD5(mobile, password);
		user.setPassword(newPwd);
		userDao.registerUser(user);
		flag=true;
		return true;
	}


	@Override
	public boolean updatePwdbyMobile(String mobile, String newPwd) {
		String pwd = MD5Util.MD5(mobile, newPwd);
		userDao.updatePwd(mobile,pwd);
		return true;
	}

	@Override
	public Boolean iszhifu(Float czdq, Long id) {
		return userDao.iszhifu(czdq,id);
	}

	@Override
	public Boolean istixian(Float txdz, Long id) {
		return userDao.istixian(txdz, id);
	}

}
